from django.contrib import admin
from .models import Publisher, Author, Book


class AuthorAdmin(admin.ModelAdmin):
    list_display = ('first_name', 'last_name', 'email')
    search_fields = ('first_name', 'last_name')


class BookAdmin(admin.ModelAdmin):
    #  列表的表头
    list_display = ('title', 'publisher', 'publication_date')
    #  列表根据出版日期进行筛选
    list_filter = ('publication_date', )
    #  在列表的表头上增加日期的筛选处理
    date_hierarchy = 'publication_date'
    #  按照出版日期倒序排列
    ordering = ('-publication_date', )
    #  作者的横向筛选
    filter_horizontal = ('authors', )
    #  设置搜索筛选出版社
    raw_id_fields = ('publisher', )


admin.site.register(Publisher)
admin.site.register(Author, AuthorAdmin)
admin.site.register(Book, BookAdmin)

